package org.extreme.schooltalk;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;

public class TabManager {
	private static final int _BASIC_MODE = 1;
	private static final int _CHG_MODE = 2;
	private OnClickListener mListener;
	
	private Context mCtx;
	View main_view;
	ImageButton tab1,tab2,tab3,tab4,tab5;
	
	public TabManager(Context ctx){
		this.mCtx = ctx;
		
		setInitTab();
	}
	public TabManager(Context ctx,View v){
		this.mCtx = ctx;
		this.main_view = v;
		setInitTab();
	}
	public TabManager(Context ctx,int resId){
		this.mCtx = ctx;
		LayoutInflater inflater = (LayoutInflater)mCtx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		main_view = inflater.inflate(resId, null);
		setInitTab();
	}
	public TabManager(Context ctx,View v,OnClickListener listener){
		this(ctx,v);
		this.mListener = listener;
	}
	
	public void setInitTab(){
		tab1 = (ImageButton)main_view.findViewById(R.id.btn_tab_1);
		tab1.setOnClickListener(listener);
		tab2 = (ImageButton)main_view.findViewById(R.id.btn_tab_2);
		tab2.setOnClickListener(listener);
		tab3 = (ImageButton)main_view.findViewById(R.id.btn_tab_3);
		tab3.setOnClickListener(listener);
		tab4 = (ImageButton)main_view.findViewById(R.id.btn_tab_4);
		tab4.setOnClickListener(listener);
		tab5 = (ImageButton)main_view.findViewById(R.id.btn_tab_5);
		tab5.setOnClickListener(listener);
		
		setInitImg();
	}
	private OnClickListener listener = new OnClickListener(){

		@Override
		public void onClick(View v) {
			Intent intent = new Intent();
			
			Class cls = null;
			String action = "";
			switch(v.getId()){
			case R.id.btn_tab_1:
				cls = FirstTabAct.class;
				//action = TabBroadCastReceiver._TAB1;
			break;
			case R.id.btn_tab_2:
				cls = SecTabAct.class;
				//action = TabBroadCastReceiver._TAB2;
			break;
			case R.id.btn_tab_3:
				cls = ThirdTabAct.class;
				//action = TabBroadCastReceiver._TAB3;
			break;
			case R.id.btn_tab_4:
				cls = ForthTabAct.class;
				//action = TabBroadCastReceiver._TAB4;
			break;
			case R.id.btn_tab_5:
				cls = SetupMainAct.class;
				//action = TabBroadCastReceiver._TAB5;
			break;
			}
			/*
			intent.setAction(TabBroadCastReceiver.TAB_ACTION);			
			intent.putExtra("tag", action);
			mCtx.sendBroadcast(intent);
			*/
			
			intent.setClass(mCtx, cls);
			//intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
			intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_CLEAR_TOP);
			mCtx.startActivity(intent);
			
		}
		
	};
	public void setListener(OnClickListener listener){
		this.mListener = listener;
	}
	public void setInitImg(){
		tab1.setImageResource(R.drawable.btn_tab_main);
		tab2.setImageResource(R.drawable.btn_tab_map);
		tab3.setImageResource(R.drawable.btn_tab_chat);
		tab4.setImageResource(R.drawable.btn_tab_club);
		tab5.setImageResource(R.drawable.btn_tab_setup);
	}
	public void setTabImgChg(int mode){
		
		setInitImg();//image init();
		
		switch(mode){
		case 1:
			tab1.setImageResource(R.drawable.btn_tab_main_n);
		break;
		case 2:
			tab2.setImageResource(R.drawable.btn_tab_map_n);
		break;
		case 3:
			tab3.setImageResource(R.drawable.btn_tab_chat_n);
		break;
		case 4:
			tab4.setImageResource(R.drawable.btn_tab_club_n);
		break;
		case 5:
			tab5.setImageResource(R.drawable.btn_tab_setup_n);
		break;			
		}
	}
	
	
}
